package remote

import (
	"context"
	"errors"
	"github.com/labstack/gommon/log"
	"xiuxian_help_tool/backend/service/remote/model"
	"xiuxian_help_tool/backend/utils/sdk"
	xiuXianba "xiuxian_help_tool/backend/utils/sdk/xiuxianba"
)

type StoreService struct {
}

var StoreServiceApp = new(StoreService)

// GetStoreList 获取商家列表
func (s *StoreService) GetStoreList(req *model.StoreListReq) (res *model.StoreList, err error) {
	ctx := context.Background()
	var resp *sdk.APIRes[model.StoreList]
	err = xiuXianba.XiuXianCli.Post("/backend/api/v1/store/list").
		SetBody(req).
		Do(ctx).Into(&resp)
	if err != nil {
		log.Error(err)
		return nil, err
	}
	if resp != nil && resp.Code == 0 {
		return nil, errors.New("获取商家列表失败")
	}
	return &resp.Data, nil
}

// GetStoreDetail 获取商家详情
func getStoreDetail(id string) (res *model.StoreDetails, err error) {
	ctx := context.Background()
	var resp *sdk.APIRes[model.StoreDetails]
	err = xiuXianba.XiuXianCli.Post("/backend/api/v1/store/detail").
		SetBody(model.IdReqBody{Id: id}).
		Do(ctx).Into(&resp)
	if err != nil {
		log.Error(err)
		return nil, err
	}
	if resp != nil && resp.Code == 0 {
		return nil, errors.New("获取商家详情失败")
	}
	return &resp.Data, nil
}
